#include "DefaultGlassController.h"
#include "Fysics/Input/WindowInput.h"
#include "Fysics/System/Time.h"

namespace Fysics
{
	void DefaultGlassController::UpdateGlassMovementInfo(ViewCamera* camera)
	{
		camera->SetRollEffect(false);
		glm::vec3 pos = camera->GetCameraPosition();
		glm::vec3 front = camera->GetCameraDirection();
		glm::vec3 right = camera->GetCameraRight();
		float moveSpeed = camera->GetMoveSpeed();
		float rotateSpeed = camera->GetRotateSpeed();
		float deltaTime = Time::GetDeltaTime();

		if (WindowInput::IsKeyPressed(FAR_KEY_W))
		{
			pos += front * moveSpeed * deltaTime;
		}
		if (WindowInput::IsKeyPressed(FAR_KEY_S))
		{
			pos -= front * moveSpeed * deltaTime;
		}
		if (WindowInput::IsKeyPressed(FAR_KEY_A))
		{
			pos -= right * moveSpeed * deltaTime;
		}
		if (WindowInput::IsKeyPressed(FAR_KEY_D))
		{
			pos += right * moveSpeed * deltaTime;
		}
		if (WindowInput::IsKeyPressed(FAR_KEY_E))
		{
			pos += glm::vec3(0, 1, 0) * moveSpeed * deltaTime;
		}
		if (WindowInput::IsKeyPressed(FAR_KEY_Q))
		{
			pos += glm::vec3(0, -1, 0) * moveSpeed * deltaTime;
		}
		camera->SetPosition(pos);

		float pitch = camera->GetPitch();
		float yaw = camera->GetYaw();
		float roll = camera->GetRoll();

		if (WindowInput::IsKeyPressed(FAR_KEY_UP) || WindowInput::IsKeyPressed(FAR_KEY_KP_8))
		{
			pitch += 2 * rotateSpeed * deltaTime;
		}
		if (WindowInput::IsKeyPressed(FAR_KEY_DOWN) || WindowInput::IsKeyPressed(FAR_KEY_KP_5))
		{
			pitch -= 2 * rotateSpeed * deltaTime;
		}
		if (WindowInput::IsKeyPressed(FAR_KEY_LEFT) || WindowInput::IsKeyPressed(FAR_KEY_KP_4))
		{
			yaw += 2 * rotateSpeed * deltaTime;
		}
		if (WindowInput::IsKeyPressed(FAR_KEY_RIGHT) || WindowInput::IsKeyPressed(FAR_KEY_KP_6))
		{
			yaw -= 2 * rotateSpeed * deltaTime;
		}
		if (WindowInput::IsKeyPressed(FAR_KEY_KP_7))
		{
			roll -= 2 * rotateSpeed * deltaTime;
		}
		if (WindowInput::IsKeyPressed(FAR_KEY_KP_9))
		{
			roll += 2 * rotateSpeed * deltaTime;
		}
		camera->SetRotation(pitch, yaw, roll);
	}
}